/*
 * @Description: 子组件暴露出去值
 * @Author: Zhanghan
 * @Date: 2025-03-04 16:06:05
 * @LastEditTime: 2025-03-04 16:26:53
 * @LastEditors: Zhanghan
 */
import { forwardRef, useImperativeHandle, useState } from "react";

//父传参
interface propsType {
  title: string;
}
// 子组件
const MyChild = forwardRef((props: propsType, ref) => {
  const [value, setValue] = useState("奥特曼，猪猪侠");

  useImperativeHandle(ref, () => ({
    getValue: () => value,
    someMethod: () => {
      setValue("闪电小子葫芦娃");
    },
  }));

  return (
    <div>
      {value}--子组件--{props.title}
    </div>
  );
});

export default MyChild;
